﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HR.Appointments.Service.ValueObjects
{
    /// <summary>
    /// Hold information about the customer.
    /// </summary>
    public class Customer 
    {
        #region Private Memebers
        private string _name;
        private string _phone;
        private string _email;
        #endregion

        #region Constructors
        private Customer(string name, string phone, string email)
        {
            _name = name;
            _phone = phone;
            _email = email;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Name of the customer
        /// </summary>
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }

        /// <summary>
        /// Customers phone number
        /// </summary>
        public string Phone
        {
            get
            {
                return _phone;
            }
            set
            {
                _phone = value;
            }
        }

        /// <summary>
        /// Email of the customer
        /// </summary>
        public string Email
        {
            get
            {
                return _email;
            }
            set
            {
                _email = value;
            }
        }
        #endregion

        #region Override Methods
        /// <summary>
        /// Determines whether the specified Object is equal to the current Object.
        /// </summary>
        /// <param name="obj">The Object to compare with the current Object.</param>
        /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType()) return false;
            Customer eql = (Customer)obj;
            return (string.Compare(eql.Phone, Phone) == 0)
                && (string.Compare(eql.Name, Name) == 0)
                && (string.Compare(eql.Email, Email) == 0);
        }

        /// <summary>
        /// Serves as a hash function for a this type.
        /// </summary>
        /// <returns>A hash code for the current Object.</returns>
        public override int GetHashCode()
        {
            return _phone.GetHashCode() ^ _name.GetHashCode() ^ _email.GetHashCode();
        }

        /// <summary>
        /// Returns a String that represents the current Object.
        /// </summary>
        /// <returns>A String that represents the current Object.</returns>
        public override string ToString()
        {
            return _phone.ToString() + " " + _name.ToString() + " " + _email.ToString();
        }
        #endregion

        #region Static Methods
        /// <summary>
        /// Creates a new Customer object
        /// </summary>
        /// <param name="name">Name of the customer</param>
        /// <param name="phone">Customers phone number</param>
        /// <param name="email">Customers email address</param>
        /// <returns></returns>
        public static Customer Create(string name, string phone, string email)
        {
            return new Customer(name, phone, email);
        }
        #endregion
    }
}
